#pragma once 

#include <boost/asio.hpp>
#include "TimerTask.h"


namespace frame {
namespace imp {
namespace asio {


class AsioTimer : public Timer, public std::enable_shared_from_this<AsioTimer> {
public:
    AsioTimer(int timerId, ITimerTask *  task, uint64_t timespan, boost::asio::io_context & ioContext);
    virtual ~AsioTimer() ;

    boost::asio::steady_timer * getAsioTimer() const{
        return timer;
    }

    void startTimer() override;
    void stopTimer() override;
    void handleTimer(const boost::system::error_code& error);

    std::function<void ()> TESTStart();
    void TESTHandle(int i);

private:
    boost::asio::steady_timer * timer;
};

class AsioTimerTasks : public TimerTasks{
public:
    AsioTimerTasks(boost::asio::io_context & ioContext);
    virtual ~AsioTimerTasks();

    void insertNoFind(int timerId, ITimerTask * task, uint64_t timespan);
    bool insert(int timerId, ITimerTask * task, uint64_t timespan);


private:
    boost::asio::io_context & ioContext;
};

} //end of namespace asio
} //end of namespace imp
} //end of namespace  frame
